import React from 'react'
import { createBehavior, createResource } from '@designable/core'
import { DnFC, useNodeIdProps } from '@designable/react'
import { AllSchemas } from '../../schemas'
import { AllLocales } from '../../locales'
import { FixedDuration as CustomFixedDuration } from '../../customComponents/FixedDuration'
import { createVoidFieldSchema } from '../Field'

export const FixedDuration: DnFC<
  React.ComponentProps<typeof CustomFixedDuration>
> = (props) => {
  const nodeIdProps = useNodeIdProps()
  return (
    <div {...nodeIdProps}>
      <CustomFixedDuration {...props} />
    </div>
  )
}

FixedDuration.Behavior = createBehavior({
  name: 'FixedDuration',
  extends: ['Field'],
  selector: (node) => node.props['x-component'] === 'FixedDuration',
  designerProps: {
    propsSchema: createVoidFieldSchema(AllSchemas.FixedDuration),
  },
  designerLocales: AllLocales.FixedDuration,
})

FixedDuration.Resource = createResource({
  icon: 'FixedValidity',
  elements: [
    {
      componentName: 'Field',
      props: {
        type: 'void',
        title: 'FixedDuration',
        'x-component': 'FixedDuration',
        'x-component-props': {
          nameCount: 'count',
          nameUnit: 'unit',
        },
      },
    },
  ],
})
